package com.cn.mobileproject.activity.fragment;

import java.util.ArrayList;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.support.v4.app.Fragment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.AdapterView.OnItemClickListener;
import android.widget.ListView;
import android.widget.Toast;

import com.cn.mobileproject.R;
import com.cn.mobileproject.bean.Task;
import com.cn.mobileproject.data.GlobalValue;
import com.cn.mobileproject.data.SystemParams;
import com.cn.mobileproject.manager.TaskManager;
import com.cn.mobileproject.view.adapter.MyTaskAdapter;
import com.handmark.pulltorefresh.library.PullToRefreshBase;
import com.net.http.HttpException;

@SuppressLint("ValidFragment")
public class CcTaskFragment extends TaskFragment {

	public CcTaskFragment(){
		super();
	}
	
	public CcTaskFragment(boolean check){
		super(check);
	}
	
	private ArrayList<Task> resultList = new ArrayList<Task>();
	
	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,Bundle savedInstanceState) {
		return super.onCreateView(inflater, container, savedInstanceState);		
	}
	
	
	protected void initComponent(){
		super.initComponent();
		adapter.setList(GlobalValue.getInstance().getCcInstructs());
		adapter.notifyDataSetChanged();
		type = 4;
	}
	
	protected void initEvent(){
		super.initEvent();
	}
	
	protected boolean isFirstInitData(){
		if(SystemParams.loadCcInstruct==0) return true;
		return false;
	}
	
	@Override
	public void initInstructData() {
		super.initInstructData();		
		if(GlobalValue.getInstance().getCcInstructs()!=null)GlobalValue.getInstance().getCcInstructs().clear();
		total = TaskManager.getInstance().initCCInstruct(GlobalValue.getInstance().getCcInstructs(),pageNo, PAGESIZE);
		if(GlobalValue.getInstance().getPublisInstructs()!=null)start = GlobalValue.getInstance().getCcInstructs().size();
	}

	@Override
	public void setAdapterList() {
		super.setAdapterList();
		adapter.setList(GlobalValue.getInstance().getCcInstructs());
		adapter.notifyDataSetChanged();
	}


	@Override
	protected void onSearchSuccess() {
		adapter.setList(GlobalValue.getInstance().getCcInstructs());
		adapter.notifyDataSetChanged();
		if(GlobalValue.getInstance().getPublisInstructs()!=null)start = GlobalValue.getInstance().getCcInstructs().size();
	}


	@Override
	protected void searchNextPageByCom() throws HttpException {
		pageNo++;
		total = TaskManager.getInstance().initCCInstruct(GlobalValue.getInstance().getCcInstructs(),pageNo, PAGESIZE);
	}

	@Override
	public void doJob(){
		if(SystemParams.loadCcInstruct==0){
			doLoadTask();
		}
		else{
			mRefreshListView.onRefreshComplete();
		}
	}
}
